import request from "../utils/request";
import axios from "axios";
const HOST_URL = "http://localhost:3001";
let token: any = localStorage.getItem("admin_token");
const http = axios.create({
    timeout: 1000,
    headers: {
        token,
    },
});

export const fetchData = () => {
    return request({
        url: "./table.json",
        method: "get",
    });
};

// 封装程序所需的数据接口
// 登录接口
export const loginFunc = (data = {}) => {
    return http.post(`${HOST_URL}/admin/login`, data).then((response) => {
        return response.data;
    });
};
// 注册接口
export const registerFunc = (data = {}) => {
    return http.post(`${HOST_URL}/admin/register`, data).then((response) => {
        return response.data;
    });
};
// 获取用户头像和昵称
export const getAvatorNickNameFunc = (data = {}) => {
    return http.get(`${HOST_URL}/admin/get_avator_nickname`, { params: data }).then((response) => {
        return response.data;
    });
};

// 获取用户列表
export const userList = (data = {}) => {
    return http.get(`${HOST_URL}/admin/list`, { params: data }).then((response) => {
        return response.data;
    });
};

// 获取用户总数量
export const userTotal = (data = {}) => {
    return http.get(`${HOST_URL}/admin/total`, { params: data }).then((response) => {
        return response.data;
    });
};

// 删除用户
export const removeUser = (data = {}) => {
    return http.post(`${HOST_URL}/admin/remove`, data).then((response) => {
        return response.data;
    });
};

// 上传图片、返回预览路径
export const uploadPhoto = (data = {}) => {
    return http.post(`${HOST_URL}/banner/upload_img`, data).then((response) => {
        return response.data;
    });
};

//删除预览图片
export const removePhotoFile = (data = {}) => {
    return http.post(`${HOST_URL}/banner/delete_img`, data).then((response) => {
        return response.data;
    });
};

// 搜索用户列表
export const searchUser = (data = {}) => {
    return http.get(`${HOST_URL}/admin/search`, { params: data }).then((response) => {
        return response.data;
    });
};

// 发布广告（轮播图）
export const addBannerInfo = (data = {}) => {
    return http.post(`${HOST_URL}/banner/addBanner`, data).then((response) => {
        return response.data;
    });
};
// 发布新闻（轮播图）
export const addNews = (data = {}) => {
    return http.post(`${HOST_URL}/newsDetail/addNews`, data).then((response) => {
        return response.data;
    });
};
// 广告列表 分页
export const bannerPaging = (data = {}) => {
    return http.post(`${HOST_URL}/banner/bannerPaging`, data).then((response) => {
        return response.data;
    });
};
// 未分页
export const bannerList = (data = {}) => {
    return http.get(`${HOST_URL}/banner/bannerList`, { params: data }).then((response) => {
        return response.data;
    });
};
// 删除广告（轮播图）
export const deleteBanner = (data = {}) => {
    return http.post(`${HOST_URL}/banner/deleteBanner`, data).then((response) => {
        return response.data;
    });
};
// 搜索轮播图列表
export const searchBanner = (data = {}) => {
    return http.get(`${HOST_URL}/banner/searchBanner`, { params: data }).then((response) => {
        return response.data;
    });
};
// 新闻分页
export const newsDetailPaging = (data = {}) => {
    return http.post(`${HOST_URL}/newsDetail/newsDetailPaging`, data).then((response) => {
        return response.data;
    });
};
// 新闻总数
export const newsDetailTotal = (data = {}) => {
    return http.get(`${HOST_URL}/newsDetail/newsDetailTotal`, { params: data }).then((response) => {
        return response.data;
    });
};
// newsSearch
export const newsSearch = (data = {}) => {
    return http.post(`${HOST_URL}/newsDetail/newsSearch`, data).then((response) => {
        return response.data;
    });
};
export const newsSearchPaging = (data = {}) => {
    return http.post(`${HOST_URL}/newsDetail/newsSearchPaging`, data).then((response) => {
        return response.data;
    });
};
export const delNews = (data = {}) => {
    return http.post(`${HOST_URL}/newsDetail/delNews`, data).then((response) => {
        return response.data;
    });
};
// 获取登录用户信息
// selectLoginUser
export const selectLoginUser = (data = {}) => {
    return http.post(`${HOST_URL}/admin/selectLoginUser`, data).then((response) => {
        return response.data;
    });
};
// 修改用户信息
export const undateUserMsg = (data = {}) => {
    return http.post(`${HOST_URL}/admin/undateUserMsg`, data).then((response) => {
        return response.data;
    });
};
// 更换头像
export const userUpdata = (data = {}) => {
    return http.post(`${HOST_URL}/admin/upload_img`, data).then((response) => {
        return response.data;
    });
};
// 保存save_img
export const save_img = (data = {}) => {
    return http.post(`${HOST_URL}/admin/save_img`, data).then((response) => {
        return response.data;
    });
};
// 删除delete_img
export const delete_img = (data = {}) => {
    return http.post(`${HOST_URL}/admin/delete_img`, data).then((response) => {
        return response.data;
    });
};
